<template>
  <div>
    <div class="local-name">
      设备类型
      <el-button
        size="small"
        class="add-button"
        type="success"
        v-if="userGuardList.includes(guard.DeviceTypeManage)"
        @click="showAdd"
      >
        <svg-icon icon-class="add"></svg-icon> 新建
      </el-button>
    </div>
    <div class="device-type-search-form-container">
      <el-form
        :model="searchForm"
        inline
      >
        <el-input
          size="small"
          clearable
          class="search-input"
          v-model="searchForm.name"
          auto-complete="off"
          placeholder="设备类型名称"
        ></el-input>
        <el-select
          size="small"
          clearable
          v-model="searchForm.active"
          placeholder="是否启用"
        >
          <el-option
            v-for="item in optionStatus"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
          :loading="searchForm.btnLoading"
        >查询</el-button>
      </el-form>
      <add
        ref="addComponent"
        @refresh="search"
      ></add>
    </div>
  </div>

</template>

<script>
import Add from './add';
export default {
  components: {
    Add
  },
  model: {
    prop: 'searchForm'
  },
  props: {
    searchForm: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data() {
    return {
      optionStatus: [
        {
          value: true,
          label: '启用'
        },
        {
          value: false,
          label: '不启用'
        }
      ]
    };
  },
  methods: {
    search() {
      this.$emit('search');
    },
    showAdd() {
      this.$refs.addComponent.showDialog();
    }
  }
};
</script>

<style lang="scss" scoped>
div {
  .local-name {
    padding: 10px 0 10px 10px;
    font-size: 24px;
    font-weight: 800;
    .el-button--success {
      float: right;
      background-color: #2c83b1 !important;
      border-color: #2c83b1 !important;
      margin-right: 10px;
    }
  }
  .device-type-search-form-container {
    background-color: #fff;
    padding: 10px 10px 0 10px;
    margin: 0 10px 10px 10px;
    .el-select {
      width: 180px;
      margin-right: 10px;
      margin-bottom: 10px;
    }
    .search-input {
      width: 180px;
      margin-right: 10px;
      margin-bottom: 10px;
    }
    .el-button--primary {
      background-color: #2c83b1 !important;
      border-color: #2c83b1 !important;
      margin-bottom: 10px;
    }
  }
}
</style>
